const { defineConfig } = require('@vue/cli-service')
const path = require('path')

const CompressionWebpackPlugin = require('compression-webpack-plugin')
const productionGzipExtensions = ['js', 'css']

function resolve(dir) {
  return path.join(__dirname, dir)
}

module.exports = defineConfig({
  transpileDependencies: true,
  devServer: {
    port: 3701,
    open: false,
    client: {
      overlay: true,
    },
    proxy: {
      '/api': {
        target: 'http://34.212.227.143:8000',
        changeOrigin: true,
        pathRewrite: {
          '^/api': '/'
        }
      }
    }
  },
  configureWebpack: config => {
    config.plugins.push(new CompressionWebpackPlugin({
      algorithm: 'gzip',
      test: new RegExp('\\.(' + productionGzipExtensions.join('|') + ')$'),
      threshold: 10240,
      minRatio: 0.8
    }))
    return {
      name: '',
      resolve: {
        alias: {
          '@': resolve('src'),
          '@views': resolve('src/views'),
          '@components': resolve('src/components')
        }
      }
    }
  },
})
